/*! jQuery Validation Plugin - v1.10.0 - 9/7/2012
* https://github.com/jzaefferer/jquery-validation
* Copyright (c) 2012 Jörn Zaefferer; Licensed MIT, GPL */

/*!
 * jQuery Validation Plugin 1.10.0
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
 * http://docs.jquery.com/Plugins/Validation
 *
 * Copyright (c) 2006 - 2011 Jörn Zaefferer
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
 
jQuery.validator.addMethod("zip", function(value, element) {
		return this.optional(element) || /^[0-9]\d{5}$/.test(value);
	},jQuery.validator.messages.zip
);

jQuery.validator.addMethod("phone", function(value, element) {
   return this.optional(element) || /^[1][3,4,5,8][0-9]{9}$/.test(value);
}, jQuery.validator.messages.phone);

jQuery.validator.addMethod("telephone", function(value, element) {
    return this.optional(element) || /^(\d{3,4})?\d{7,8}?(\d{3,4})$/.test(value);
}, jQuery.validator.messages.telephone);

jQuery.validator.addMethod("fax", function(value, element) {
    return this.optional(element) || /^(\d{3,4}-?)?\d{7,8}$/.test(value);
}, jQuery.validator.messages.fax);

jQuery.validator.addMethod("idcard", function(value, element) {
	//return this.optional(element) || /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{2}[\dxX]$/.test(value) || /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}[\dxX]$/.test(value);
	var obj=CIF2_Valid_SFZ(value);
	var flag=false;
	if(obj.code==0){
		flag=true;
	}
	//jQuery.validator.messages.idcard=obj.msg;
	return this.optional(element) || flag;
}, jQuery.validator.messages.idcard);

jQuery.validator.addMethod("lettersanddigits", function(value, element) {
	return this.optional(element) || /^[a-zA-Z0-9]*$/.test(value);
}, jQuery.validator.messages.idcard);

jQuery.validator.addMethod("charlength", function(value, element,param) {
	return this.optional(element) || value.length==param;
}, jQuery.validator.messages.charlength);
jQuery.validator.addMethod("dateformat", function(value, element) {
	return this.optional(element) || ("长期" == value || /(^(?:(?!0000)[0-9]{4}(?:(?:0[1-9]|1[0-2])(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])(?:29|30)|(?:0[13578]|1[02])31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)0229)$)/.test(value));
}, jQuery.validator.messages.dateformat);
jQuery.validator.addMethod("birthdayformat", function(value, element) {
	return this.optional(element) || (/(^(?:(?!0000)[0-9]{4}(?:(?:0[1-9]|1[0-2])(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])(?:29|30)|(?:0[13578]|1[02])31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)0229)$)/.test(value));
}, jQuery.validator.messages.birthdayformat);
jQuery.validator.addMethod("maxlength_CN", function(value, element, param) {
	var iMaxLen = Number(param);
	var iLen = value.replace(/[^\x00-\xff]/g, "%%").length;
	return this.optional(element) || (iLen <= iMaxLen);
},jQuery.validator.messages.maxlength_CN);
jQuery.validator.addMethod("agecheck", function(value, element, param) {//param[0]=18年前的今天(yyyymmdd) param[1]=开户最小年龄参数
	var flag=/^\d{8}$/.test(value);
	if(flag){//合法日期后判断是否大于18周岁
		if(value-param[0]<=0){
			flag=true;
		}else{
			flag=false;
		}
	}
	return this.optional(element) || flag;
}, jQuery.validator.messages.agecheck);
jQuery.validator.addMethod("zjbhcheck", function(value, element, param) {// param 证件类别参数检测
	var flag =true;
	if(param==4){//4 港澳居民来往大陆通行证  M+8位数字 或 H+8位数字
		flag=/^H\d{8}$/.test(value)||/^M\d{8}$/.test(value);
	}else if(param==15){//15 台湾居民来往大陆通行证  8位数字 或
		flag=/^\d{8}$/.test(value);
	}else if(param==16){
		//16 港澳台居民身份证
		flag=/^H\d{8}$/.test(value)||/^M\d{8}$/.test(value)||/^\d{8}$/.test(value);
	}
	return this.optional(element) || flag;
}, jQuery.validator.messages.zjbhcheck);
//基金公司账户规则校验
jQuery.validator.addMethod("jjgsjy", function(value, element, param) {
	// param 上海A=0 上海基金公司=1，深圳A=2 深圳基金公司 =3  上海B股 =4  深圳B股=5
	var flag =true;
	if(param==0){//上海A
		flag=/^(A|B|D|E)\d{9}$/.test(value);
	}else if(param==1){//上海基金公司
		flag=/^F\d{9}$/.test(value);
	}else if(param==2){//深圳A
		flag=/^(0|4)\d{9}$/.test(value);
	}else if(param==3){//深圳基金公司
		flag=/^(001\d{7})|(05\d{8})$/.test(value);
	}else if(param==4){//上海B股
		flag=/^C\d{9}$/.test(value);
	}else if(param==5){//深圳B股
		flag=/^(2|4)\d{9}$/.test(value);
	}
	var iLen = value.replace(/[^\x00-\xff]/g, "%%").length;
	return this.optional(element) || flag&&iLen==10;
}, jQuery.validator.messages.idcard);
jQuery.validator.addMethod("htxybh", function(value, element, param) {//param=10 表示最大长度等于10
	//^[A-Za-z0-9]+$匹配由数字和26个英文字母组成的字符串
	var flag=false;
	if(param!=0){//如果param=0表示不控制长度
		flag=50-value.length>=0&&param-value.length>=0&&/^[A-Za-z0-9_.\$]+$/.test(value);
	}else{
		flag=50-value.length>=0&&/^[A-Za-z0-9_.\$]+$/.test(value);
	}
	return this.optional(element) || flag;
}, jQuery.validator.messages.htxybh);

jQuery.validator.addMethod("address", function(value, element) {
	// 地址检查
	var checkRet = ((value.indexOf("省") > 0 ||value.indexOf("市") > 0 || value.indexOf("区") > 0 ||  value.indexOf("县") > 0) &&
					value.replace(/[^\x00-\xff]/g, "%%").length >= 16);
	return this.optional(element) || checkRet;
},jQuery.validator.messages.address);

jQuery.validator.addMethod("dateYXQ", function(value, element, param) {
	// param 服务器当天时间YYYYMMDD
	return this.optional(element) || ("长期" == value || value- param>=0);
},jQuery.validator.messages.dateYXQ);

jQuery.validator.addMethod("dateYXQS", function(value, element, param) {
	// param 服务器当天时间YYYYMMDD
	return this.optional(element) || (value- param<=0);
},jQuery.validator.messages.dateYXQS);

jQuery.validator.addMethod("notequal", function(value, element, param) {
	// param 当前需要比较的值
	return this.optional(element) || (param != value || value.length==0 || param.length==0);
},jQuery.validator.messages.notequal);

jQuery.validator.addMethod("banknum", function(value, element) {
	var tmpVlaue = value.replace(/\s+/g,""); 
	var iLen = tmpVlaue.replace(/[^\x00-\xff]/g, "%%").length;
	return this.optional(element) || (((/^[0-9]*$/.test(tmpVlaue))&&(iLen <= 20&&iLen>=15)));
},jQuery.validator.messages.banknum);
jQuery.validator.addMethod("bankpwd", function(value, element, param) {
	var tmpVlaue = value.replace(/\s+/g,""); 
	var iLen = tmpVlaue.replace(/[^\x00-\xff]/g, "%%").length;
	return this.optional(element) || (((/^[0-9]*$/.test(tmpVlaue))&&(iLen == param)));
},jQuery.validator.messages.bankpwd);

